package com.swotplus.admin.web.weixin;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swotplus.common.core.AjaxResult;
import com.swotplus.framework.web.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import com.swotplus.system.weixin.service.WxcmsMsgTextService;
import java.util.*;
import com.swotplus.system.weixin.entity.WxcmsMsgText;
import com.swotplus.system.weixin.service.WxcmsMsgTextService;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hugang
 * @since 2020-06-04
 */
@Controller
@RequestMapping("/wxcmsMsgText")
public class WxcmsMsgTextController extends BaseController {

    private String prefix = "/weixin/msg/text";


    @Autowired
    private WxcmsMsgTextService wxcmsMsgTextService;

    @RequestMapping("/list")
    @RequiresPermissions("wxcmsMsgText:view")
    public String toHtml(){
         return prefix + "/list";
    }

    @RequestMapping("/listData")
    @RequiresPermissions("wxcmsMsgText:list")
    @ResponseBody
    public AjaxResult listData(WxcmsMsgText wxcmsMsgText, Integer page, Integer limit){
        try
        {
            QueryWrapper<WxcmsMsgText> wrapper = new QueryWrapper<>();
            Page<WxcmsMsgText> pageList = wxcmsMsgTextService.page(new Page<>(page,limit), wrapper);
            return AjaxResult.success("成功", (int) pageList.getTotal(),pageList.getRecords());
        } catch (Exception e)
        {
            return AjaxResult.warn(e.getMessage());
        }

    }

    /**
     * 新增保存
     */
    @RequestMapping("/add")
    @RequiresPermissions("wxcmsMsgText:add")
    @ResponseBody
    public AjaxResult add(WxcmsMsgText wxcmsMsgText){

        try
        {
            return toAjax(wxcmsMsgTextService.save(wxcmsMsgText));
        } catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/remove")
    @RequiresPermissions("wxcmsMsgText:del")
    @ResponseBody
    public  AjaxResult delBatch(String ids){

        try
        {
            List<String> ListStr = Arrays.asList(ids.split(",")).stream().map(s -> s.trim()).collect(Collectors.toList());
            return toAjax(wxcmsMsgTextService.removeByIds(ListStr));
        } catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
    * 编辑
    */
    @RequestMapping("/edit")
    @RequiresPermissions("wxcmsMsgText:edit")
    @ResponseBody
    public AjaxResult edit(WxcmsMsgText wxcmsMsgText){
       try
        {
            return toAjax(wxcmsMsgTextService.updateById(wxcmsMsgText));
        } catch (Exception e)
        {
            return error(e.getMessage());
        }


    }

}

